<script setup>
import { ref, watch } from 'vue'
const num = ref(0)
const jiayi = () => {
  num.value += 1
}
// 可以给watch监听一个赋值，当条件达成时不在监听  ref监听
const x = watch(num, () => {
  console.log(num.value)
  if (num.value >= 10) {
    x()
  }
})
</script>

<template>
  <div>
    <span>年龄{{ num }}</span
    ><br />
    <button @click="jiayi">点击年龄加一</button>
  </div>
</template> 

